<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
 * Description of category_model
 *
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Admin_listing_model extends CI_Model {

	//put your code here


	function __construct() {
		parent::__construct();
		log_message('debug', 'Init Model Initialized');
	}

	//-- Get listings(Multi Row) --//
	function get_listings($status = NULL) {

		$sql = "select * from profile where status = $status order by id DESC limit 20";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $query->result();
		}else{
			return false;
		}

	}

	/*For PAGINATION*/
	/*function get_listings($featured=false, $status=1,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
	$limit = "";
	if (isset($num) && isset($offset))
		$limit = " order by (id) desc limit $offset, $num";
	$sql = "select * from business_master " . $subcond . $limit;
	$query = $this->db->query($sql);
	$result = $query->result();
	return $result;
	}*/
	//--Inactive listing function for pagination-- rahul sinha//
	function get_inactive_listings($featured=false, $status=51,$num=NULL, $offset=NULL) {
		$subcond = "where status=$status";
		$limit = "";
		if (isset($num) && isset($offset))
			$limit = " order by (id) desc limit $offset, $num";
		$sql = "select * from business_master " . $subcond . $limit;
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}

	function search($search=null){
		$sql = "Select * from business_master where title like '$search%' order by id desc";
		$query = $this->db->query($sql);
		$result = $query->result();
		if($result){
			return $query->result();
		}else{
			return false;
		}


	}

	function change_status($id, $status) {
		if ($status == 1) {
			$sql = "update profile set status=51 where id=$id";
		}
		if ($status == 51) {
			$sql = "update profile set status=1 where id=$id";
		}
		$this->db->query($sql);
	}
	/*
	 function change_status($status=NUll, $id=NULL)
	 {

	$sql="update business_master set status=$status where id=$id";
	$this->db->query($sql);
	}
	*/


	function delete($id=NULL)
	{
		$this->db->where('id',$id);
		$this->db->delete('profile');

		$this->db->where('listing_id', $id);
		$this->db->delete('term');


	}

	function getListing($id=NULL) {
		$sql = "select * from profile where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}

	function getSpecialities(){
		$sql = "select * from category_tree where status = 51";
		$result = $this->db->query($sql)->result();
		if($result) return $result;
	}
	function getPayment($listing_id=0,$key_id=0){
		$sql = "select * from term where listing_id=$listing_id and term_value=$key_id and status = 51";
		$result = $this->db->query($sql)->result();
		if($result) return $result;
	}
	function get_listing_keyword($listing_id=0,$key_id=0){
		$sql = "select * from term where listing_id=$listing_id and term_value=$key_id limit 1";
		$query = $this->db->query($sql);
		if($query->num_rows()!=0){
			return $query->row()->term_value;
		}else{
			return 0;
		}
	}
	function getStates(){
		$sql = "select * from state where status = 51";
		$result = $this->db->query($sql)->result();
		if($result) return $result;
	}
	
	
	function get_business_name($id= NULL)
	{
		$sql = "select * from business_master where id= $id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
			
	}

	function get_members($status = 51) {
		if (!$this->db->table_exists('member_master')) {
			return FALSE;
		}
		$sql = "select * from member_master where status=$status order by id";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}

	function getQualification($profile_id=0){

		$sql = "select * from qualification where profile_id = $profile_id";
		$result=$this->db->query($sql)->result();
		if($result){
			return $result;
		}else{
			return false;
		}
	}

	function getQualificationinof($id=NULL) {
		$sql = "select * from qualification where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}

	function deleteQualification($id=NULL){
		$sql = "delete from qualification where id=$id";
		$this->db->query($sql);
	}
	
	
	function getLicense($profile_id=0){
	
		$sql = "select * from license where profile_id = $profile_id";
		$result=$this->db->query($sql)->result();
		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	function getLicenseinof($id=NULL) {
		$sql = "select * from license where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}
	
	function deleteLicense($id=NULL){
		$sql = "delete from license where id=$id";
		$this->db->query($sql);
	}
	
	function getAssociation($profile_id=0){
	
		$sql = "select * from association where profile_id = $profile_id";
		$result=$this->db->query($sql)->result();
		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	function getAssociationinof($id=NULL) {
		$sql = "select * from association where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}
	
	function deleteAssociation($id=NULL){
		$sql = "delete from association where id=$id";
		$this->db->query($sql);
	}

	function getAwards($profile_id=0){
	
		$sql = "select * from awards where profile_id = $profile_id";
		$result=$this->db->query($sql)->result();
		if($result){
			return $result;
		}else{
			return false;
		}
	}
	
	function getAwardinof($id=NULL) {
		$sql = "select * from awards where id=$id";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}
	
	function deleteAward($id=NULL){
		$sql = "delete from awards where id=$id";
		$this->db->query($sql);
	}
	
	public function tutorial_image($listing_id) {
		$sql = "select * from profile where id='$listing_id' ";
		$query = $this->db->query($sql);
		$row = $query->row();
		return $row;
	}
}